package com.example.port.service.impl;

import com.example.port.entity.Client;
import com.example.port.mapper.ClientMapper;
import com.example.port.service.ClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClientServiceImpl implements ClientService {
    
    private final ClientMapper clientMapper;
    
    @Autowired
    public ClientServiceImpl(ClientMapper clientMapper) {
        this.clientMapper = clientMapper;
    }
    
    @Override
    public int insertClient(Client client) {
        // 检查是否已设置ID，如果没有，则自动生成ID
        if (client.getClientId() == null) {
            Integer maxId = clientMapper.getMaxClientId();
            client.setClientId(maxId + 1);
        }
        return clientMapper.insert(client);
    }
    
    @Override
    public List<Client> getAllClients() {
        return clientMapper.selectAll();
    }
    
    @Override
    public Client getClientById(Integer clientId) {
        return clientMapper.selectById(clientId);
    }
    
    @Override
    public int updateClient(Client client) {
        return clientMapper.update(client);
    }
    
    @Override
    public int deleteClient(Integer clientId) {
        return clientMapper.delete(clientId);
    }
} 
